<?php
set_include_path('..');
include_once('settings.php');
session_start();

$result["success"] = 0;
$result["message"] = MESSAGE_SUCCESS;

try {
    if (!isset($_SESSION["user"])){
        throw new Exception(MESSAGE_NOT_LOGGED_IN);
    }


    if (!isset($_POST["action"])){
        throw new Exception(MESSAGE_FAILED);
    }

    $action = $_POST["action"];

    $administration = new OrderAdministration();

    switch($action){
        case("payOrder"):
            $id = $_POST["id"];
            $data = $administration->PayOrder($id);
            $result["data"] = $data;
            $result["success"] = $data ? true : false;
            break;
        case("freeOrder"):
            $id = $_POST["id"];
            $data = $administration->FreeOrder($id);
            $result["data"] = $data;
            $result["success"] = $data ? true : false;
            break;
        default:
            throw new Exception(MESSAGE_FAILED);
            break;
    }

} catch (Exception $e){
    $result["success"] = 0;
    $result["message"] = $e->getMessage();
}

echo json_encode($result);